<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="${base}/resources/admin/css/common.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="${base}/resources/admin/js/jquery.js"></script>
    <script type="text/javascript" src="${base}/resources/admin/js/common.js"></script>
    <script type="text/javascript" src="${base}/resources/admin/js/list.js"></script>
    <script type="text/javascript">
        $().ready(function(){
            [@flash_message /]
            var $disableButton = $("#disableButton");
            var $selectAll = $("#selectAll");
            var $ids = $("#listTable input[name='ids']");
            var $contentRow = $("#listTable tr:gt(0)");
            // 全选
            $selectAll.click( function() {
                var $this = $(this);
                var $enabledIds = $("#listTable input[name='ids']:enabled");
                if ($this.prop("checked")) {
                    $enabledIds.prop("checked", true);
                    if ($enabledIds.filter(":checked").size() > 0) {
                        $disableButton.removeClass("disabled");
                        $contentRow.addClass("selected");
                    } else {
                        $disableButton.addClass("disabled");
                    }
                } else {
                    $enabledIds.prop("checked", false);
                    $disableButton.addClass("disabled");
                    $contentRow.removeClass("selected");
                }
            });

            // 选择
            $ids.click( function() {
                var $this = $(this);
                if ($this.prop("checked")) {
                    $this.closest("tr").addClass("selected");
                    $disableButton.removeClass("disabled");
                } else {
                    $this.closest("tr").removeClass("selected");
                    if ($("#listTable input[name='ids']:enabled:checked").size() > 0) {
                        $disableButton.removeClass("disabled");
                    } else {
                        $disableButton.addClass("disabled");
                    }
                }
            });

            // 禁用
            $disableButton.click( function() {
                var $this = $(this);
                if ($this.hasClass("disabled")) {
                    return false;
                }
                var $checkedIds = $("#listTable input[name='ids']:enabled:checked");
                $.dialog({
                    type: "warn",
                    content: "确认禁用",
                    ok: message("admin.dialog.ok"),
                    cancel: message("admin.dialog.cancel"),
                    onOk: function() {
                        $.ajax({
                            url: "disable",
                            type: "POST",
                            data: $checkedIds.serialize(),
                            dataType: "json",
                            cache: false,
                            success: function(message) {
                                $.message(message);
                                if (message.type == "success") {
//                                setTimeout(function() {
//                                    location.reload(true);
//                                }, 2000);
                                    $checkedIds.each(function (i, obj) {
                                        var id = $(obj).data("index");

                                        var tdStatus = $(obj).parent().parent().find(".status");
                                        tdStatus.empty();
                                        tdStatus.html('<span class="red">用户不可用<\/span>');

                                        var tdOpration = $(obj).parent().parent().find(".operation");
                                        tdOpration.empty();
                                        tdOpration.append('<a href="edit?id='+id+'">[编辑]</a><a href="#" onclick="enableUser(\''+id+'\',this)" >[启用]<\/a>');

                                        $(obj).attr("disabled","disabled");
                                        $(obj).attr("title","已被禁用");
                                    });
                                }
                                $disableButton.addClass("disabled");
                                $selectAll.prop("checked", false);
                                $checkedIds.prop("checked", false);
                            }
                        });
                    }
                });
            });
        });

    </script>
</head>
<body class="list" >
[#-- android机型管理--]
<form id="listForm" action="list" method="get">
    <div class="path">
        <a href="${base}/androidType/index">${message("admin.path.index")}</a> &raquo;
        NFC机型管理列表<span>(${message("admin.page.total", pager.total)})</span>

        <div class="menuWrap searchWrap">
            <div class="search">
                <span id="searchPropertySelect" class="arrow"> 选择字段 &nbsp;</span>
                <input type="text" id="searchValue" name="searchValue" value="${pager.pageable.searchValue}" maxlength="200" />
                <button type="submit">&nbsp;</button>
            </div>
            <div class="popupMenu">
                <ul id="searchPropertyOption">
                    <li>
                        <a href="javascript:;"[#if pager.pageable.searchProperty == "t.andriod_type"] class="current"[/#if] val="t.andriod_type">anriod机型</a>
                    </li>
                    <li>
                        <a href="javascript:;"[#if pager.pageable.searchProperty == "t.factory"] class="current"[/#if] val="t.factory">厂商</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>

    <div class="bar">
        <a href="add" class="iconButton">
            <span class="addIcon">&nbsp;</span>增加
        </a>
        <div class="buttonWrap">
           <!-- <a href="javascript:;" id="disableButton" class="iconButton disabled">
                <span class="deleteIcon">&nbsp;</span>禁用
            </a>-->
            <div class="menuWrap">
                <a href="javascript:;" id="pageSizeSelect" class="button">
                    每页显示<span class="arrow">&nbsp;</span>
                </a>
                <div class="popupMenu">
                    <ul id="pageSizeOption">
                        <li>
                            <a href="javascript:;"[#if pager.pageable.pageSize == 10] class="current"[/#if] val="10">10</a>
                        </li>
                        <li>
                            <a href="javascript:;"[#if pager.pageable.pageSize == 20] class="current"[/#if] val="20">20</a>
                        </li>
                        <li>
                            <a href="javascript:;"[#if pager.pageable.pageSize == 50] class="current"[/#if] val="50">50</a>
                        </li>
                        <li>
                            <a href="javascript:;"[#if pager.pageable.pageSize == 100] class="current"[/#if] val="100">100</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

    </div>
    <table id="listTable" class="list">
        <tr>
            <th class="check" >
                <input type="checkbox" id="selectAll" />
            </th>
            <th>
                <a href="javascript:;" class="sort" name="su.login_name">厂商</a>
            </th>
            <th>
                <a href="javascript:;" name="su.email">机型类型</a>
            </th>
            <th>
                <a href="javascript:;" class="sort" name="su.name">机型说明</a>
            </th>

            <th width="150">
                <span>状态</span>
            </th>
            <th>
                <a href="javascript:;" class="sort" name="su.create_date">备注</a>
            </th>
            <th>
                <span>操作</span>
            </th>
        </tr>
        [#list pager.content as androidType]
        <tr>
            <td>
                <input data-index="${androidType.id}" type="checkbox" class="checkbox" name="ids"  value="${androidType.id}"  />
            </td>
            <td>
                ${androidType.factory}
            </td>
            <td>
                ${androidType.andriod_type}
            </td>
            <td>
                ${androidType.addriod_comment}
            </td>
            <td class="status">
                [#if androidType.status]
                <span class="green">启用NFC</span>
                [#else]
                <span class="red">禁用NFC</span>
                [/#if]
            </td>
            <td>
                ${androidType.remarks}
            </td>
            <td class="operation">
                <a href="edit?id=${androidType.id}">[编辑]</a>
            </td>
        </tr>
        [/#list]
    </table>

    [#if (pager.content?size > 0)]
    [@pagination pageNumber = pager.pageable.pageNumber totalPages = pager.pageable.totalPages]
    [#include "/admin/include/pagination.html"]
    [/@pagination]
    [#else ]
    <div class="norecord">
        <span>没有记录!</span>
    </div>
    [/#if]
</form>
</body>
</html>